package com.xyd.Servlet;


import com.xyd.Biz.FatherOrderBiz;
import com.xyd.Biz.Impl.FatherOrderBizImpl;
import com.xyd.Entity.FatherOrder;
import com.xyd.Util.JsonServlet;
import com.xyd.Util.PageUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@WebServlet("/html/manage/getAllFatherOrderServlet")
public class getAllFatherOrderServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String userNameKeyWord = request.getParameter("userNameKeyWord");
        String orderIdKeyWord = request.getParameter("orderIdKeyWord");
        int pageSize = Integer.parseInt(request.getParameter("pageSize"));
        int pageNum = Integer.parseInt(request.getParameter("pageNum"));

        FatherOrderBiz fatherOrderBiz = new FatherOrderBizImpl();
        int fatherOrderCount = fatherOrderBiz.getFatherOrderCountByNameKeyWord(userNameKeyWord,orderIdKeyWord);
        //使用分页工具类，根据总数居的条数算出总页数，第二个参数是工具类中每页显示的默认条数，可以按需求更改
        int totalPages = PageUtil.getTotalPages(fatherOrderCount,PageUtil.PAGE_SIZE);

       List<FatherOrder> fatherOrderList = fatherOrderBiz.getFatherOrderByPagesAndNameKeyWord(userNameKeyWord,orderIdKeyWord,pageSize,pageNum);



        Map<String, Object> maps = new HashMap<String, Object>();
        maps.put("fatherOrderList", fatherOrderList);
        maps.put("pageNum", pageNum);
        maps.put("totalPages", totalPages);

        JsonServlet.getJson(request, response, maps);


    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
